﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ExtendDictionary
{
    public static class StringExtender
    {
        public static IDictionary<string,string> ToDictionary(this string s)
        {
            var keyValuePairs = SplitIntoKeyValuePairs(s, ';');

            return  AddPairsToDictionary(keyValuePairs);
        }

        internal static string[] SplitIntoKeyValuePairs(string s, char seperator)
        {
            return s.Split(seperator);  
        }

        internal static IDictionary<string,string> AddPairsToDictionary(string[] keyValuePair)
        {
            var outputDictionary = new Dictionary<string, string>();
            
            foreach (var pair in keyValuePair)
            {
                var seperatedKeyValuePair = SplitIntoKeyValuePairs(pair, '=');
                outputDictionary.Add(seperatedKeyValuePair[0], seperatedKeyValuePair[1]);
            }

            return outputDictionary;
        }
    }
}
